package com.ht.safe.entity;

import com.ht.safe.entity.ext.Action;
import com.ht.safe.entity.ext.AuthenticationType;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Type;
import org.springframework.data.jpa.domain.AbstractPersistable;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * 认证模板, 用于为通行人员进行权限认证设置
 */
@Entity
@Table(name="T_Credential_Template")
public class CredentialTemplate extends AbstractPersistable<Integer> {


    @Column(unique = true, nullable = false)
    @Index(name="idx_credential_template_name")
    private String name;

    /**
     * 描述
     */
    private String description;

    @Enumerated(EnumType.STRING)
    @Column(name = "authentication_type")
    private AuthenticationType authenticationType;

    /**
     * 有效期起始时间, 精确到分钟
     */
    @Column(name = "active_start")
    @Temporal(TemporalType.TIMESTAMP)
    private Date activeStart;

    /**
     * 有效期结束时间
     */
    @Column(name = "active_end")
    @Temporal(TemporalType.TIMESTAMP)
    private Date activeEnd;

    /**
     * pin码长度
     */
    @Column(name = "pin_code_len")
    private Integer pinCodeLen;

    /**
     * 胁迫码长度
     */
    @Column(name = "duress_code_len")
    private Integer duressCodeLen;

    /**
     * 胁迫等级(0-99)
     */
    @Column(name = "duress_authority")
    private Integer duressAuthority;

    /**
     * 时间规则特权
     */
    @Column(name = "time_rule")
    @Type(type = "org.hibernate.type.NumericBooleanType")
    private Boolean timeRule;

    /**
     * 线路规则特权(潜回)
     */
    @Column(name = "line_rule")
    @Type(type = "org.hibernate.type.NumericBooleanType")
    private Boolean lineRule;

    /**
     * 多人规则特权
     */
    @Column(name = "ab_rule")
    @Type(type = "org.hibernate.type.NumericBooleanType")
    private Boolean abRule;

    /**
     * 延长开门时间,单位为秒，允许为0或空值
     */
    @Column(name = "access_time_extension")
    private Integer accessTimeExtension;

    /**
     * 认证时需要操作器执行的操作, 如果是空则忽略该项
     */
    @Enumerated(EnumType.STRING)
    private Action action;

    /**
     * 证章模板
     */
    @Column(name = "badge_template")
    private BadgeTemplate badgeTemplate;

    /**
     * 人组信息
     */
    private String memberGroup;

    /**
     * 允许通过的门组列表
     */
/*    @ManyToMany
    @JoinTable(name="T_Member_Door_Groups",
            joinColumns=
            @JoinColumn(name="member_ID", referencedColumnName="ID"),
            inverseJoinColumns=
            @JoinColumn(name="door_group_ID", referencedColumnName="ID")
    )
    private List<DoorGroup> doorGroups;*/

    /**
     * 允许通过的区域列表
     */
//    @ManyToMany
//    @JoinTable(name="T_Member_Area",
//            joinColumns=
//            @JoinColumn(name="member_ID", referencedColumnName="ID"),
//            inverseJoinColumns=
//            @JoinColumn(name="area_ID", referencedColumnName="ID")
//    )
//    private List<Area> areas;
    @ElementCollection(fetch=FetchType.EAGER)
    private List<String> areas;

	public CredentialTemplate() {
	}

	public CredentialTemplate(Integer id) {
		this.setId(id);
	}

}
